import { EventTouch, Node, UITransform, Vec3 } from "cc";
import { ecsclass, ECSSystem } from "../../../app-core/ecs/ECSWorld";

@ecsclass("InputSystem")
export class InputSystem extends ECSSystem {
    constructor(readonly inputNode: Node) {
        super();
    }

    start(): void {
        super.start();

        this.inputNode.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
    }


    stop(): void {

        this.inputNode.off(Node.EventType.TOUCH_START, this.onTouchStart, this);

        super.stop();
    }

    onTouchStart(event: EventTouch) {
        const transform = this.inputNode.getComponent(UITransform);
        if (!transform) return;

        const location = event.getUILocation();
        const position = transform.convertToNodeSpaceAR(new Vec3(location.x, location.y));
    }
}